package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC53 {

    public int maxSubArray(int[] nums) {
        int curSum = 0, res = nums[0];
        for (int num : nums) {
            curSum = Math.max(curSum + num, num);
            res = Math.max(res, curSum);
        }

        return res;
    }

    public static void main(String[] args) {
        LC53 an = new LC53();
        int[] arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4};

        System.out.println(an.maxSubArray(arr));
    }
}
